package com.tfswx.nginxcleanhc;

import com.sun.jna.Platform;
import org.apache.tomcat.util.http.fileupload.FileUtils;
import org.apache.tomcat.util.http.fileupload.IOUtils;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.io.ClassPathResource;

import java.io.*;

@SpringBootApplication
public class App {
    private static final String[] files = {"nginx_cache_purge"};

    public static void main(String[] args) {

        for (String filePath : files) {
            ClassPathResource classPathResource = new ClassPathResource("lib/" + filePath);
            if (!classPathResource.exists()) {
                classPathResource = new ClassPathResource("lib/" + Platform.RESOURCE_PREFIX + "/" + filePath);
                if (!classPathResource.exists()) {
                    continue;
                }
            }
            try (InputStream inputStream = classPathResource.getInputStream();
                 OutputStream outputStream = new FileOutputStream(filePath);) {
                IOUtils.copy(inputStream, outputStream);
            } catch (IOException e) {
                throw new RuntimeException("文件拷贝失败", e);
            }
        }

        SpringApplication.run(App.class, args);
    }

}
